﻿@page "/Archive/Batch/Index"
@page "/Archive/Batch/Index/{Token}"
@using iTeamyou.LTS.UI.Models;
@using iTeamyou.LTS.UI.Shared.Components;

<h5 style="margin-top: 1.5rem;">入库管理</h5>
<div style="margin-top: 2rem;">
    @*<Button Text="新建批次" OnClick="@Add" />*@
    <Button Text="编辑" OnClick="@EditBtn" IsDisabled="@(SelectedBatches.Count != 1)" />
    <PopConfirmButton Color="Color.Danger" IsDisabled="@(SelectedBatches.Count == 0)" OnConfirm="(() => Delete(SelectedBatches))" ConfirmIcon="fa-solid fa-triangle-exclamation text-danger" ConfirmButtonColor="Color.Danger" Content="确定删除选中的记录吗？">删除</PopConfirmButton>
    <Button Text="导出" OnClick="@Export" IsDisabled="IsUnauth" />
</div>
@*
*@
<Table style="margin-top: 1rem;" TItem="Core.Models.Batch"
       IsPagination="true" PageItemsSource="@PageItemsSource" IsStriped="true" ShowLineNo="true"
       CustomerSearchModel="@BatchSearchModel" SearchMode="SearchMode.Top" ShowSearchText="true" ShowSearch="true"
       OnDoubleClickRowCallback="@Edit"
       SelectedRows="@SelectedBatches" SelectedRowsChanged="@SelectChanged" IsMultipleSelect="true"
       ShowSkeleton="true" ShowResetButton="true" ShowEmpty="true"
       OnQueryAsync="@OnQueryAsync" IsAutoRefresh="@IsAutoRefresh" AutoRefreshInterval="2000">
    <TableColumns>
        <TableColumn @bind-Field="@context.ProductId" Width="80" Readonly="true" Text="商品SKU">
            <Template Context="value">
                @if (value.Value != null)
                {
                    <div>@ProductService.Get(value.Value)?.PId</div>
                }
            </Template>
        </TableColumn>
        <TableColumn @bind-Field="@context.ProductId" Width="80" Readonly="true" Text="商品UPC">
            <Template Context="value">
                @if (value.Value != null)
                {
                    <div>@ProductService.Get(value.Value)?.UPC</div>
                }
            </Template>
        </TableColumn>
        <TableColumn @bind-Field="@context.ProductId" Width="80" Readonly="true" Text="商品名称">
            <Template Context="value">
                @if (value.Value != null)
                {
                    <div>@ProductService.Get(value.Value)?.Name</div>
                }
            </Template>
        </TableColumn>
        @*<TableColumn @bind-Field="@ProductService.Get(context.ProductId).UPC" Width="80" Readonly="true" />
        <TableColumn @bind-Field="@ProductService.Get(context.ProductId).Name" Width="200" Readonly="true" />*@
        <TableColumn @bind-Field="@context.Quantity" Width="60" Readonly="true" />
        <TableColumn @bind-Field="@context.SupplierName" Width="120" Readonly="true" />
        <TableColumn @bind-Field="@context.EntryDatetime" Width="80" Sortable="true" Readonly="true" />
        <TableColumn @bind-Field="@context.OrderNumber" Width="80" Readonly="true" />
        <TableColumn @bind-Field="@context.Number" Width="80" Readonly="true" />
        <TableColumn @bind-Field="@context.LicenseNum" Width="80" Text="证照数">
            <Template Context="value">
                @if (value.Value == 0)
                {
                    <Tag Color="Color.Dark">共 0 个证照</Tag>
                }
                else
                {
                    <Tag Color="Color.Primary">共 @value.Value 个证照</Tag>
                }
            </Template>
        </TableColumn>
    </TableColumns>
    <CustomerSearchTemplate>
        @if (context is BatchSearchModel model)
        {
            <BatchSearch @bind-Value="@model" />
        }
    </CustomerSearchTemplate>
</Table>